﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VgoCardChange.Models.Objects;
using VgoCardChange.Models;
using System.Globalization;

namespace VgoCardChange.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/

        AdminModels adm;
        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public ActionResult Admin() 
        {
            return View();
        }
        public ActionResult Login(User user)
        {
             adm = new AdminModels();
            if (adm.CheckAdminLogin(user.UserName, user.PassWord))
            {
                Session["UserAdmin"] = user.UserName;
                return RedirectToAction("Index");
            }
            else
                return Redirect("Admin/?LoginFail=true");
        }
        [HttpGet]
        public ActionResult AdminLogout() 
        {
            Session["UserAdmin"] = null;
            return RedirectToAction("Admin");
        }
        #region activeDiscount
        [HttpGet]
        public ActionResult ActiveDisCount() 
        {
             adm = new AdminModels();
            ViewData["SupplierLst"] = new SelectList(adm.GetListCardSupplier(), "CardSupplierID", "CardSupplierName");
            return View("Discount");
        }

        [HttpPost]
        public ActionResult SaveDiscount(Discount discount, string SupplierLst, string NgayBdKm, string ThangBdKm, string NamBdKm, string NgayKtKm, string ThangKtKm, string NamKtKm)
        {
            //Get Start Discount Date
           // discount.StartDate = Convert.ToDateTime(NgayBdKm + "/" + ThangBdKm + "/" + NamBdKm); 
            discount.StartDate = DateTime.Parse(NgayBdKm + "/" + ThangBdKm + "/" + NamBdKm, CultureInfo.CreateSpecificCulture("vi-VN"));
            //Get End discount Date
            discount.EndDate = DateTime.Parse(NgayKtKm + "/" + ThangKtKm + "/" + NamKtKm, CultureInfo.CreateSpecificCulture("vi-VN"));
            /*----------------------------*/
            discount.CardSupplierID = SupplierLst;
            adm = new AdminModels();
            string userName = Session["UserAdmin"].ToString();
            discount.UserID = adm.GetUserID(userName); 
            adm.SaveDisCount(discount);
            return RedirectToAction("ActiveDisCount");
        }
        #endregion 
    }
}
